package edu.ccut.saturn.studio.wfg.dialog.startactivitydialog;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolTip;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.search.SaturnFileSearcher.SearchResult;
import edu.ccut.saturn.studio.core.search.dialog.OneCompontentSearchDialog;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.wfg.dialog.RevertCandidate;
import edu.ccut.saturn.studio.wfg.dialog.SelectionCandidate;
import edu.ccut.saturn.studio.wfg.dialog.TableViewerContentProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.FormDataAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.MyCellModifierFormDataAttribute;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForAdd;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForDoubleClick;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForEdit;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.ExtendAttributeForLogicKeyLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.LogicKeyAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.MyCellModifierExtendAttributeForLogicKey;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicDialogForAdd;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicDialogForEdit;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicParameterAddDialog;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicParameterEditDialog;
import edu.ccut.saturn.studio.wfg.wfgmodel.ExtendAttributeForLogicKey;
import edu.ccut.saturn.studio.wfg.wfgmodel.FormDataAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.LogicKeyAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnStartLimit;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnStartNode;

public class SaturnStartActivityDialog extends TitleAreaDialog {
	
	private SaturnStartNode saturnStartNode = new SaturnStartNode();
	
	private CellEditor[] cellEditor;
	
	// 基本信息
	private Label activityIdLabel, activityNameLabel, startPolicyLabel, timeLimitLabel, 
				  offsetModeLabel, descriptionLabel;

	private Text activityIdText, activityNameText, timeLimitText, descriptionText;

	private Combo startPolicyCombo,  offsetModelCombo;
	
	// logicKey表单信息
	private LogicKeyAttribute logicKeyAttribute;

	private List<SaturnAttribute> logicKeyTemp;
	
	private TableViewer tableViewer;
	
	private Table table;
	
	private Button insertButton, deleteButton, upbutton, downbutton, editButton;
	
	// formData表单信息
	private List<SaturnAttribute> formDataTemp;
	
	private List<SaturnAttribute> fdListTemp = new ArrayList<SaturnAttribute>();
	
	private List<String> nameListTemp = new ArrayList<String>();
	
	private SaturnAttribute fd1, fd2, fd3, fd4, fd5, fd6;
	
	private TableViewer tableViewer_2;
	
	private Table table_2;
	
	private Button insertButton_2, deleteButton_2, upbutton_2, downbutton_2,editButton_2;

	// 启动限制的东西
	private SaturnStartLimit startLimit;
	
	private List<SaturnAttribute> extendAttributeForLogicKeyList;
	
	private List<SaturnAttribute> extendAttributeForLogicKeyListTemp;
	
	private Group group_5;
	
	private Button directStartButton, regulationStartButton, insertButton_5, editButton_5, deleteButton_5;
	
	private Label logicLabel, emplifyLabel;
	
	private Text logicText;
	
	private TableViewer tableViewer_5;
	
	private Table table_5;
	
	public SaturnStartActivityDialog(Shell parentShell, SaturnStartNode saturnStartNode) {
		super(parentShell);
		this.saturnStartNode = saturnStartNode;
		this.copyLogicKeyList(saturnStartNode.getLogicKeyList());
		this.copyFormDataList(saturnStartNode.getFormDataAttributeList());
		this.startLimit = this.saturnStartNode.getSaturnStartLimit();
		this.extendAttributeForLogicKeyList = this.startLimit.getExtendAttributeForLogicKey();
		this.copyStartLimitList(extendAttributeForLogicKeyList);
	}

	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);
		setMessage(SelectionCandidate.SETTING_ATTRIBUTE + saturnStartNode.getName()); 
		return contents;
	}

	@Override
	protected Control createDialogArea(Composite parent) {

		getShell().setText(SelectionCandidate.ATTRIBUTE_SETTING); 
		setTitleImage(Activator.getImage(Images.SATURN_ICONS_MAXNAME));
		Composite area = (Composite) super.createDialogArea(parent);

		TabFolder tabFolder;
		tabFolder = new TabFolder(area, SWT.NONE);
		tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		// 汽泡提示框
		final ToolTip tip = new ToolTip(getShell(), SWT.BALLOON | SWT.ICON_WARNING |SWT.ARROW);
		tip.setMessage(Messages.getString("SaturnStartActivityDialog.InputNumber"));   //$NON-NLS-1$
		tip.setVisible(false);

		// 基本信息选项卡
		final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText(Messages.getString("SaturnStartActivityDialog.BaseInformation"));   //$NON-NLS-1$

		final Group group = new Group(tabFolder, SWT.NONE);
		group.setText(Messages.getString("SaturnStartActivityDialog.BaseInformationDefine"));   //$NON-NLS-1$
		tabItem.setControl(group);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		group.setLayout(gridLayout);
		
		activityIdLabel = new Label(group, SWT.NONE);
		activityIdLabel.setText(Messages.getString("SaturnStartActivityDialog.AvtionID"));   //$NON-NLS-1$
		
		activityIdText = new Text(group, SWT.BORDER | SWT.READ_ONLY);
		activityIdText.setTextLimit(50);
		activityIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		activityNameLabel = new Label(group, SWT.NONE);
		activityNameLabel.setText(Messages.getString("SaturnStartActivityDialog.ActionName"));   //$NON-NLS-1$

		activityNameText = new Text(group, SWT.BORDER);
		activityNameText.setTextLimit(50);
		activityNameText.setFocus();
		activityNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		startPolicyLabel = new Label(group, SWT.NONE);
		startPolicyLabel.setText(Messages.getString("SaturnStartActivityDialog.Startor"));   //$NON-NLS-1$

		startPolicyCombo = new Combo(group, SWT.READ_ONLY);
		startPolicyCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
		startPolicyCombo.setItems(SelectionCandidate.startPolicyCandidate);

		timeLimitLabel = new Label(group, SWT.NONE);
		timeLimitLabel.setText(Messages.getString("SaturnStartActivityDialog.TimeLimited"));   //$NON-NLS-1$

		timeLimitText = new Text(group, SWT.BORDER);
		timeLimitText.setTextLimit(50);
		timeLimitText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		offsetModeLabel = new Label(group, SWT.NONE);
		offsetModeLabel.setText(Messages.getString("SaturnStartActivityDialog.Brnace"));   //$NON-NLS-1$

		offsetModelCombo = new Combo(group, SWT.READ_ONLY);
		offsetModelCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
		offsetModelCombo.setItems(SelectionCandidate.offsetModelCandidate);

		descriptionLabel = new Label(group, SWT.NONE);
		descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		descriptionLabel.setText(Messages.getString("SaturnStartActivityDialog.Decription"));   //$NON-NLS-1$

		descriptionText = new Text(group, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
		descriptionText.setTextLimit(200);
		final GridData gd_descriptionText = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd_descriptionText.heightHint = 70;
		descriptionText.setLayoutData(gd_descriptionText);

		// logicKey表单信息选项卡
		final TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
		tabItem_1.setText(Messages.getString("SaturnStartActivityDialog.Logic"));   //$NON-NLS-1$

		final Group group_1 = new Group(tabFolder, SWT.NONE);
		group_1.setText(Messages.getString("SaturnStartActivityDialog.LogicDefine"));   //$NON-NLS-1$
		tabItem_1.setControl(group_1);
		final GridLayout gridLayout_1 = new GridLayout();
		group_1.setLayout(gridLayout_1);

		Composite composite1 = new Composite(group_1, SWT.NONE);
		final GridData gd_composite1 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite1.setLayoutData(gd_composite1);
		composite1.setLayout(new FormLayout());

		tableViewer = new TableViewer(composite1, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		table = tableViewer.getTable();
		final FormData fd_table = new FormData();
		fd_table.bottom = new FormAttachment(100, -8);
		fd_table.right = new FormAttachment(100, -100);
		fd_table.top = new FormAttachment(0, 10);
		fd_table.left = new FormAttachment(0, 5);
		table.setLayoutData(fd_table);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		tableViewer.setContentProvider(new TableViewerContentProvider());
		tableViewer.setLabelProvider(new LogicKeyAttributeLabelProvider());

		final TableColumn newColumnTableColumn = new TableColumn(table,	SWT.NONE);
		newColumnTableColumn.setWidth(390);
		newColumnTableColumn.setText(Messages.getString("SaturnStartActivityDialog.Express"));   //$NON-NLS-1$

		insertButton = new Button(composite1, SWT.NONE);
		insertButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent selectionevent) {
				openAddDialog();
			}
		});
		final FormData fd_addbutton = new FormData();
		fd_addbutton.bottom = new FormAttachment(table, 23, SWT.TOP);
		fd_addbutton.top = new FormAttachment(table, 0, SWT.TOP);
		fd_addbutton.right = new FormAttachment(100, -20);
		fd_addbutton.left = new FormAttachment(100, -75);
		insertButton.setLayoutData(fd_addbutton);
		insertButton.setText(SelectionCandidate.INSERT_BUTTON);

		deleteButton = new Button(composite1, SWT.NONE);
		deleteButton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				logicKeyAttribute = (LogicKeyAttribute) selection.getFirstElement();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);
				} else {
					List<SaturnAttribute> logicKeyListForDelete = (List<SaturnAttribute>) tableViewer.getInput();
					logicKeyListForDelete.remove(logicKeyAttribute);
					tableViewer.setInput(logicKeyListForDelete);
				}
			}
		});
		final FormData fd_deletebutton = new FormData();
		fd_deletebutton.top = new FormAttachment(insertButton, 5, SWT.BOTTOM);
		fd_deletebutton.right = new FormAttachment(insertButton, 0, SWT.RIGHT);
		fd_deletebutton.left = new FormAttachment(100, -75);
		deleteButton.setLayoutData(fd_deletebutton);
		deleteButton.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton = new Button(composite1, SWT.NONE);
		upbutton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);
				} else {
					Table table_up = tableViewer.getTable();
					if (tableViewer.getTable() != null) {
						int i = table_up.getSelectionIndex();
						if (i > 0) {
							SaturnAttribute lka = logicKeyTemp.get(i);
							List<SaturnAttribute> logicKeyListForUp = (List<SaturnAttribute>) tableViewer.getInput();
							logicKeyListForUp.remove(lka);
							tableViewer.remove(lka);
							logicKeyListForUp.add(i - 1, lka);
							tableViewer.setInput(logicKeyListForUp);
							table_up.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton = new FormData();
		fd_upbutton.top = new FormAttachment(deleteButton, 5, SWT.BOTTOM);
		fd_upbutton.right = new FormAttachment(deleteButton, 0, SWT.RIGHT);
		fd_upbutton.left = new FormAttachment(100, -75);
		upbutton.setLayoutData(fd_upbutton);
		upbutton.setText(SelectionCandidate.UP_BUTTON); 

		downbutton = new Button(composite1, SWT.NONE);
		downbutton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					Table table_down = tableViewer.getTable();
					if (tableViewer.getTable() != null) {
						int i = table_down.getSelectionIndex();
						if (i < tableViewer.getTable().getItemCount() - 1) {
							SaturnAttribute lka = logicKeyTemp.get(i);
							List<SaturnAttribute> logicKeyListForDown = (List<SaturnAttribute>) tableViewer.getInput();
							logicKeyListForDown.remove(lka);
							tableViewer.remove(lka);
							logicKeyListForDown.add(i + 1, lka);
							tableViewer.setInput(logicKeyListForDown);
							table_down.setSelection(i + 1);
						}
					}
				}
			}
		});
		final FormData fd_downbutton = new FormData();
		fd_downbutton.top = new FormAttachment(upbutton, 5, SWT.BOTTOM);
		fd_downbutton.right = new FormAttachment(upbutton, 0, SWT.RIGHT);
		fd_downbutton.left = new FormAttachment(100, -75);
		downbutton.setLayoutData(fd_downbutton);
		downbutton.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton = new Button(composite1, SWT.NONE);
		editButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					logicKeyAttribute = (LogicKeyAttribute) selection.getFirstElement();
					openEditDialog(logicKeyAttribute);
					tableViewer.refresh();
				}
			}
		});
		final FormData fd_editbutton = new FormData();
		fd_editbutton.top = new FormAttachment(downbutton, 5, SWT.BOTTOM);
		fd_editbutton.right = new FormAttachment(downbutton, 0, SWT.RIGHT);
		fd_editbutton.left = new FormAttachment(100, -75);
		editButton.setLayoutData(fd_editbutton);
		editButton.setText(SelectionCandidate.EDIT_BUTTON);

		// formData表单信息选项卡
		final TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
		tabItem_2.setText(Messages.getString("SaturnStartActivityDialog.StartPameter"));   //$NON-NLS-1$

		final Group group_2 = new Group(tabFolder, SWT.NONE);
		group_2.setText(Messages.getString("SaturnStartActivityDialog.StartParameterDefine"));   //$NON-NLS-1$
		tabItem_2.setControl(group_2);
		final GridLayout gridLayout_2 = new GridLayout();
		group_2.setLayout(gridLayout_2);

		Composite composite2 = new Composite(group_2, SWT.NONE);
		final GridData gd_composite2 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite2.setLayoutData(gd_composite2);
		composite2.setLayout(new FormLayout());

		tableViewer_2 = new TableViewer(composite2, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		tableViewer_2.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(final DoubleClickEvent arg0) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				SaturnAttribute attribute = (SaturnAttribute) selection.getFirstElement();
				openFormDataDialogFromDoubleClick(attribute);
			}
		});
		table_2 = tableViewer_2.getTable();
		final FormData fd_table_2 = new FormData();
		fd_table_2.bottom = new FormAttachment(100, -8);
		fd_table_2.right = new FormAttachment(100, -100);
		fd_table_2.top = new FormAttachment(0, 10);
		fd_table_2.left = new FormAttachment(0, 5);
		table_2.setLayoutData(fd_table_2);
		table_2.setLinesVisible(true);
		table_2.setHeaderVisible(true);
		tableViewer_2.setContentProvider(new TableViewerContentProvider());
		tableViewer_2.setLabelProvider(new FormDataAttributeLabelProvider());

		tableViewer_2.setColumnProperties(new String[] { "id", "key", "name",
				"type", "accessType", "required" });
		cellEditor = new CellEditor[6];
		cellEditor[0] = null;
		cellEditor[1] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[2] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[3] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataTypes, SWT.READ_ONLY);
		cellEditor[4] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataReadWrite, SWT.READ_ONLY);
		cellEditor[5] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataRequired, SWT.READ_ONLY);

		tableViewer_2.setCellEditors(cellEditor);
		tableViewer_2.setCellModifier(new MyCellModifierFormDataAttribute(tableViewer_2));

		final TableColumn newColumnTableColumn_id = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_id.setWidth(80);
		newColumnTableColumn_id.setText("ID");

		final TableColumn newColumnTableColumn_0 = new TableColumn(table_2,	SWT.NONE);
		newColumnTableColumn_0.setWidth(80);
		newColumnTableColumn_0.setText(Messages.getString("SaturnStartActivityDialog.Expresstion"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_1 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_1.setWidth(80);
		newColumnTableColumn_1.setText(Messages.getString("SaturnStartActivityDialog.Name"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_2 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_2.setWidth(80);
		newColumnTableColumn_2.setText(Messages.getString("SaturnStartActivityDialog.Type"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_3 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_3.setWidth(80);
		newColumnTableColumn_3.setText(Messages.getString("SaturnStartActivityDialog.ReadType"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_4 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_4.setWidth(80);
		newColumnTableColumn_4.setText(Messages.getString("SaturnStartActivityDialog.IsNeed"));   //$NON-NLS-1$

		insertButton_2 = new Button(composite2, SWT.NONE);
		insertButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				openFormDataDialog();
			}
		});
		final FormData fd_addbutton_2 = new FormData();
		fd_addbutton_2.bottom = new FormAttachment(table_2, 23, SWT.TOP);
		fd_addbutton_2.top = new FormAttachment(table_2, 0, SWT.TOP);
		fd_addbutton_2.right = new FormAttachment(100, -20);
		fd_addbutton_2.left = new FormAttachment(100, -75);
		insertButton_2.setLayoutData(fd_addbutton_2);
		insertButton_2.setText(SelectionCandidate.INSERT_BUTTON); 

		deleteButton_2 = new Button(composite2, SWT.NONE);
		deleteButton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					formDataTemp.remove(fdAttribute);
					orderFormData(formDataTemp);
					tableViewer_2.setInput(formDataTemp);
				}
			}
		});
		final FormData fd_deletebutton_2 = new FormData();
		fd_deletebutton_2.top = new FormAttachment(insertButton_2, 5, SWT.BOTTOM);
		fd_deletebutton_2.right = new FormAttachment(insertButton_2, 0, SWT.RIGHT);
		fd_deletebutton_2.left = new FormAttachment(100, -75);
		deleteButton_2.setLayoutData(fd_deletebutton_2);
		deleteButton_2.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton_2 = new Button(composite2, SWT.NONE);
		upbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					if (tableViewer_2.getTable() != null) {
						int i = table.getSelectionIndex();
						if (i > 0) {
							formDataTemp.remove(fdAttribute);
							formDataTemp.add(i - 1, fdAttribute);
							orderFormData(formDataTemp);
							tableViewer_2.setInput(formDataTemp);
							table.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton_2 = new FormData();
		fd_upbutton_2.top = new FormAttachment(deleteButton_2, 5, SWT.BOTTOM);
		fd_upbutton_2.right = new FormAttachment(deleteButton_2, 0, SWT.RIGHT);
		fd_upbutton_2.left = new FormAttachment(100, -75);
		upbutton_2.setLayoutData(fd_upbutton_2);
		upbutton_2.setText(SelectionCandidate.UP_BUTTON); 

		downbutton_2 = new Button(composite2, SWT.NONE);
		downbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					int i = table.getSelectionIndex();
					if (i < tableViewer_2.getTable().getItemCount() - 1) {
						formDataTemp.remove(fdAttribute);
						formDataTemp.add(i + 1, fdAttribute);
						orderFormData(formDataTemp);
						tableViewer_2.setInput(formDataTemp);
						table.setSelection(i + 1);
					}
				}
			}
		});
		final FormData fd_downbutton_2 = new FormData();
		fd_downbutton_2.top = new FormAttachment(upbutton_2, 5, SWT.BOTTOM);
		fd_downbutton_2.right = new FormAttachment(upbutton_2, 0, SWT.RIGHT);
		fd_downbutton_2.left = new FormAttachment(100, -75);
		downbutton_2.setLayoutData(fd_downbutton_2);
		downbutton_2.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton_2 = new Button(composite2, SWT.NONE);
		editButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					editFormDataDialog((FormDataAttribute) selection.getFirstElement());
					tableViewer_2.refresh();
				}
			}
		});
		final FormData fd_editbutton_2 = new FormData();
		fd_editbutton_2.top = new FormAttachment(downbutton_2, 5, SWT.BOTTOM);
		fd_editbutton_2.right = new FormAttachment(downbutton_2, 0, SWT.RIGHT);
		fd_editbutton_2.left = new FormAttachment(100, -75);
		editButton_2.setLayoutData(fd_editbutton_2);
		editButton_2.setText(SelectionCandidate.EDIT_BUTTON); 

		// 启动限制
		final TabItem tabItem_5 = new TabItem(tabFolder, SWT.NONE);
		tabItem_5.setText(Messages.getString("SaturnStartActivityDialog.StartLimit"));   //$NON-NLS-1$

		Composite composite5 = new Composite(tabFolder, SWT.NONE);
		tabItem_5.setControl(composite5);
		final GridData gd_composite5 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite5.setLayoutData(gd_composite5);
		composite5.setLayout(new FormLayout());

		group_5 = new Group(composite5, SWT.NONE);
		group_5.setText(Messages.getString("SaturnStartActivityDialog.StartLimitDefine"));   //$NON-NLS-1$
		final FormData fd_group_5 = new FormData();
		fd_group_5.bottom = new FormAttachment(100, -5);
		fd_group_5.right = new FormAttachment(100, -5);
		fd_group_5.left = new FormAttachment(0, 5);
		fd_group_5.top = new FormAttachment(0, 5);
		group_5.setLayoutData(fd_group_5);
		group_5.setLayout(new FormLayout());

		directStartButton = new Button(group_5, SWT.RADIO);
		directStartButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(directStartButton.getSelection()==true){
					logicLabel.setEnabled(false);
					logicText.setEnabled(false);
					emplifyLabel.setEnabled(false);
					
					table_5.setEnabled(false);
					insertButton_5.setEnabled(false);
					editButton_5.setEnabled(false);
					deleteButton_5.setEnabled(false);
				}
			}
		});
		final FormData fd_directStart = new FormData();
		fd_directStart.top = new FormAttachment(0, 25);
		fd_directStart.left = new FormAttachment(0, 25);
		fd_directStart.right = new FormAttachment(0, 95);
		directStartButton.setLayoutData(fd_directStart);
		directStartButton.setText(Messages.getString("SaturnStartActivityDialog.start"));   //$NON-NLS-1$

		regulationStartButton = new Button(group_5, SWT.RADIO);
		regulationStartButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(regulationStartButton.getSelection()==true){
					logicLabel.setEnabled(true);
					logicText.setEnabled(true);
					emplifyLabel.setEnabled(true);
					
					table_5.setEnabled(true);
					insertButton_5.setEnabled(true);
					editButton_5.setEnabled(true);
					deleteButton_5.setEnabled(true);
				}
			}
		});
		final FormData fd_regulationStart = new FormData();
		fd_regulationStart.left = new FormAttachment(directStartButton, 0, SWT.LEFT);
		fd_regulationStart.right = new FormAttachment(directStartButton, 0, SWT.RIGHT);
		fd_regulationStart.top = new FormAttachment(directStartButton, 20, SWT.BOTTOM);
		regulationStartButton.setLayoutData(fd_regulationStart);
		regulationStartButton.setText(Messages.getString("SaturnStartActivityDialog.RuleStart"));   //$NON-NLS-1$

		logicLabel = new Label(group_5, SWT.NONE);
		final FormData fd_logicLabel = new FormData();
		fd_logicLabel.top = new FormAttachment(regulationStartButton, 20, SWT.BOTTOM);
		fd_logicLabel.left = new FormAttachment(directStartButton, 0, SWT.LEFT);
		fd_logicLabel.right = new FormAttachment(directStartButton, -20, SWT.RIGHT);
		logicLabel.setLayoutData(fd_logicLabel);
		logicLabel.setText(Messages.getString("SaturnStartActivityDialog.logic"));   //$NON-NLS-1$

		logicText = new Text(group_5, SWT.BORDER);
		final FormData fd_logicText = new FormData();
		fd_logicText.right = new FormAttachment(100,-40);
		fd_logicText.top = new FormAttachment(logicLabel,-5, SWT.TOP);
		fd_logicText.left = new FormAttachment(directStartButton, 0, SWT.RIGHT);
		logicText.setLayoutData(fd_logicText);

		emplifyLabel = new Label(group_5, SWT.NONE);
		emplifyLabel.addMouseTrackListener(new MouseTrackAdapter() {
			public void mouseEnter(final MouseEvent e) {
				emplifyLabel.setImage(Activator.getImage(Images.AMPLIFY_MINUS));  
			}
			public void mouseExit(final MouseEvent e) {
				emplifyLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));  
			}
		});
		emplifyLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));  
		final FormData fd_emplifyLabel = new FormData();
		fd_emplifyLabel.top = new FormAttachment(logicText, 0, SWT.TOP);
		fd_emplifyLabel.left = new FormAttachment(logicText, 10, SWT.RIGHT);
		emplifyLabel.setLayoutData(fd_emplifyLabel);
		emplifyLabel.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
			
			OneCompontentSearchDialog searchDialog = new OneCompontentSearchDialog(
					Display.getDefault().getShells()[0], saturnStartNode);
			if ( searchDialog.open() == Window.OK) {
				SearchResult  logicKey = (SearchResult)searchDialog.getFirstResult();
				logicText.setText(logicKey.getKey());
				
				Document document = logicKey.getDocument(); 
				NodeList nodelist = document.getDocumentElement().getElementsByTagName("start");
				Node startNode = nodelist.item(0);
				if(startNode!=null){
					List<Node> parametersNodeList = new ArrayList<Node>();
					NodeList paraList = startNode.getChildNodes();
					for(int i = 0; i < paraList.getLength(); i++){
						if("parameters".equals(paraList.item(i).getNodeName())){
							NodeList pList = paraList.item(i).getChildNodes();
							for(int j = 0; j < pList.getLength(); j++){
								if("parameter".equals(pList.item(j).getNodeName())){
									parametersNodeList.add(pList.item(j));
								}
							}
						}
					}
					
					for (Node n: parametersNodeList){
						ExtendAttributeForLogicKey ea = new ExtendAttributeForLogicKey();
						String strID = SaturnW3CUtil.getNodeAttributeValue(n, "id");
						ea.setId(strID);
						NodeList vk = n.getChildNodes();
						for(int i = 0; i < vk.getLength(); i++){
							if("value-key".equals(vk.item(i).getNodeName())){
								String strValueKey = SaturnW3CUtil.getChildNodeValue(n, "value-key");
								ea.setParameter(strValueKey);
							}
						}
						extendAttributeForLogicKeyListTemp.add(ea);
					}
				}
				tableViewer_5.setInput(extendAttributeForLogicKeyListTemp);
			}
		  }
		});

		tableViewer_5 = new TableViewer(group_5, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		table_5 = tableViewer_5.getTable();
		final FormData fd_table_5 = new FormData();
		fd_table_5.top = new FormAttachment(logicLabel, 20, SWT.BOTTOM);
		fd_table_5.left = new FormAttachment(directStartButton, 0, SWT.LEFT);
		fd_table_5.bottom = new FormAttachment(100, -10);
		fd_table_5.right = new FormAttachment(100, -85);
		table_5.setLayoutData(fd_table_5);
		table_5.setLinesVisible(true);
		table_5.setHeaderVisible(true);
		tableViewer_5.setContentProvider(new TableViewerContentProvider());
		tableViewer_5.setLabelProvider(new ExtendAttributeForLogicKeyLabelProvider());
		
		tableViewer_5.setColumnProperties(new String[] { "id", "parameter"});
		cellEditor = new CellEditor[3];
		cellEditor[0] = null;
		cellEditor[1] = new TextCellEditor(tableViewer_5.getTable());

		tableViewer_5.setCellEditors(cellEditor);
		tableViewer_5.setCellModifier(new MyCellModifierExtendAttributeForLogicKey(tableViewer_5));
		
		final TableColumn startLimitTableColumnID = new TableColumn(table_5, SWT.NONE);
		startLimitTableColumnID.setWidth(100);
		startLimitTableColumnID.setText("ID");

		final TableColumn startLimitTableColumnParameter = new TableColumn(table_5, SWT.NONE);
		startLimitTableColumnParameter.setWidth(270);
		startLimitTableColumnParameter.setText("parameter");

		insertButton_5 = new Button(group_5, SWT.NONE);
		insertButton_5.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				openStartLimit();
			}
		});
		final FormData fd_insertButton_5 = new FormData();
		fd_insertButton_5.top = new FormAttachment(table_5, 10, SWT.TOP);
		fd_insertButton_5.left = new FormAttachment(100, -70);
		fd_insertButton_5.right = new FormAttachment(100, -15);
		insertButton_5.setLayoutData(fd_insertButton_5);
		insertButton_5.setText(SelectionCandidate.INSERT_BUTTON);

		editButton_5 = new Button(group_5, SWT.NONE);
		editButton_5.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_5.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					editStartLimit((ExtendAttributeForLogicKey)selection.getFirstElement());
					tableViewer_5.refresh();
				}
			}
		});
		final FormData fd_editButton_5 = new FormData();
		fd_editButton_5.top = new FormAttachment(insertButton_5, 10, SWT.BOTTOM);
		fd_editButton_5.left = new FormAttachment(insertButton_5, 0, SWT.LEFT);
		fd_editButton_5.right = new FormAttachment(insertButton_5, 0, SWT.RIGHT);
		editButton_5.setLayoutData(fd_editButton_5);
		editButton_5.setText(SelectionCandidate.EDIT_BUTTON);

		deleteButton_5 = new Button(group_5, SWT.NONE);
		deleteButton_5.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_5.getSelection();
				SaturnAttribute extendAttributeForLogicKey = (SaturnAttribute)selection.getFirstElement();
				if(selection.isEmpty()){
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);
				} else {
					extendAttributeForLogicKeyListTemp.remove(extendAttributeForLogicKey);
					orderExtendAttributeForLogic(extendAttributeForLogicKeyListTemp);
					tableViewer_5.setInput(extendAttributeForLogicKeyListTemp);
				}
			}
		});
		final FormData fd_deleteButton_5 = new FormData();
		fd_deleteButton_5.top = new FormAttachment(editButton_5, 10, SWT.BOTTOM);
		fd_deleteButton_5.left = new FormAttachment(editButton_5, 0, SWT.LEFT);
		fd_deleteButton_5.right = new FormAttachment(editButton_5, 0, SWT.RIGHT);
		deleteButton_5.setLayoutData(fd_deleteButton_5);
		deleteButton_5.setText(SelectionCandidate.DELETE_BUTTON);
		
		initial();
		
		/**
		 * 名称不可为空
		 * 
		 * */
		activityNameText.addModifyListener(new ModifyListener(){
			public void modifyText(ModifyEvent e) {
				errorInformationHint();
			}
		});
		
		/**
		 * 时间必须为数字
		 * 
		 * */
		timeLimitText.addVerifyListener(new VerifyListener() {
			public void verifyText(final VerifyEvent e) {
				Pattern pattern = Pattern.compile("[0-9]\\d*"); 
				Matcher matcher = pattern.matcher(e.text);
				if (matcher.matches()) {
					e.doit = true;
				} else if (e.text.length() > 0) {
					e.doit = false;
					tip.setLocation(getShell().getBounds().x + group.getBounds().x
							+ timeLimitText.getLocation().x
							, getShell().getBounds().y + group.getBounds().y
							+ timeLimitText.getLocation().y + 100);
					tip.setVisible(true);
				} else {
					e.doit = true;
				}
			}
		});
		
		/**
		 * 启动策略事件触发
		 * 
		 * */
		startPolicyCombo.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent e) {
				if(startPolicyCombo.getText().trim().equals(SelectionCandidate.startPolicyCandidate[1])){
					if(formDataTemp.size()==0){
						createStartParameter();
						copyFormDataList(fdListTemp);
						tableViewer_2.setInput(formDataTemp);
					}else{
						createStartParameter();
						for (int i = 0; i < formDataTemp.size(); i++) {
							nameListTemp.add(((FormDataAttribute)formDataTemp.get(i)).getName().trim());
						}
						if(!nameListTemp.contains("business_type")){
							((FormDataAttribute) fd1).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd1);
						}
						if(!nameListTemp.contains("business_id")){
							((FormDataAttribute) fd2).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd2);
						}
						if(!nameListTemp.contains("priority")){
							((FormDataAttribute) fd3).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd3);
						}
						if(!nameListTemp.contains("name")){
							((FormDataAttribute) fd4).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd4);
						}
						if(!nameListTemp.contains("description")){
							((FormDataAttribute) fd5).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd5);
						}
						if(!nameListTemp.contains("creator_department")){
							((FormDataAttribute) fd6).setId(String.valueOf(formDataTemp.size()+1));
							formDataTemp.add(fd6);
						}
						
						tableViewer_2.setInput(formDataTemp);
						nameListTemp.clear();
					}
				}
			}
		});
		
		return area;
	}
	
	private void createStartParameter() {
		fdListTemp.clear();

		fd1 = new FormDataAttribute();
		((FormDataAttribute) fd1).setId("1");
		((FormDataAttribute) fd1).setKey("business_type");
		((FormDataAttribute) fd1).setName("business_type");
		((FormDataAttribute) fd1).setType("text");
		((FormDataAttribute) fd1).setAccessType("read-write");
		((FormDataAttribute) fd1).setRequired("true");

		fd2 = new FormDataAttribute();
		((FormDataAttribute) fd2).setId("2");
		((FormDataAttribute) fd2).setKey("business_id");
		((FormDataAttribute) fd2).setName("business_id");
		((FormDataAttribute) fd2).setType("text");
		((FormDataAttribute) fd2).setAccessType("read-write");
		((FormDataAttribute) fd2).setRequired("true");

		fd3 = new FormDataAttribute();
		((FormDataAttribute) fd3).setId("3");
		((FormDataAttribute) fd3).setKey("priority");
		((FormDataAttribute) fd3).setName("priority");
		((FormDataAttribute) fd3).setType("text");
		((FormDataAttribute) fd3).setAccessType("read-write");
		((FormDataAttribute) fd3).setRequired("true");

		fd4 = new FormDataAttribute();
		((FormDataAttribute) fd4).setId("4");
		((FormDataAttribute) fd4).setKey("name");
		((FormDataAttribute) fd4).setName("name");
		((FormDataAttribute) fd4).setType("text");
		((FormDataAttribute) fd4).setAccessType("read-write");
		((FormDataAttribute) fd4).setRequired("true");

		fd5 = new FormDataAttribute();
		((FormDataAttribute) fd5).setId("5");
		((FormDataAttribute) fd5).setKey("description");
		((FormDataAttribute) fd5).setName("description");
		((FormDataAttribute) fd5).setType("text");
		((FormDataAttribute) fd5).setAccessType("read-write");
		((FormDataAttribute) fd5).setRequired("true");

		fd6 = new FormDataAttribute();
		((FormDataAttribute) fd6).setId("6");
		((FormDataAttribute) fd6).setKey("creator_department");
		((FormDataAttribute) fd6).setName("creator_department");
		((FormDataAttribute) fd6).setType("text");
		((FormDataAttribute) fd6).setAccessType("read-write");
		((FormDataAttribute) fd6).setRequired("true");
		
		fdListTemp.add(fd1);
		fdListTemp.add(fd2);
		fdListTemp.add(fd3);
		fdListTemp.add(fd4);
		fdListTemp.add(fd5);
		fdListTemp.add(fd6);
	}

	private void openStartLimit(){
		SaturnVocationalLogicParameterAddDialog addDialog = new SaturnVocationalLogicParameterAddDialog(
				Display.getDefault().getShells()[0], extendAttributeForLogicKeyListTemp);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer_5.setInput(extendAttributeForLogicKeyListTemp);
		}
	}
	
	private void editStartLimit(ExtendAttributeForLogicKey extendAttributeForLogicKey){
		SaturnVocationalLogicParameterEditDialog editDialog = new SaturnVocationalLogicParameterEditDialog(
				Display.getDefault().getShells()[0], extendAttributeForLogicKey);
		editDialog.open();
	}
	
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		super.createButtonsForButtonBar(parent);
		getButton(IDialogConstants.OK_ID).setEnabled(true);
	}
	
	@SuppressWarnings("unchecked")
	private void openAddDialog(){
		SaturnVocationalLogicDialogForAdd addDialog = new SaturnVocationalLogicDialogForAdd(Display.getDefault().getShells()[0], logicKeyTemp, saturnStartNode);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer.setInput(logicKeyTemp);
		}
	}
	
	@SuppressWarnings("unchecked")
	private void openEditDialog(LogicKeyAttribute logicKeyAttribute){
		SaturnVocationalLogicDialogForEdit editDialog = new SaturnVocationalLogicDialogForEdit(Display.getDefault().getShells()[0], logicKeyAttribute, saturnStartNode);
		editDialog.open();
	}

	protected Point getInitialSize() {
		return new Point(540, 480);
	}

	private void openFormDataDialog() {
		SaturnFormDataDialogForAdd addDialog = new SaturnFormDataDialogForAdd(Display.getDefault().getShells()[0], formDataTemp, saturnStartNode);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer_2.setInput(formDataTemp);
		}
	}

	private void editFormDataDialog(FormDataAttribute form) {
		SaturnFormDataDialogForEdit editDialog = new SaturnFormDataDialogForEdit(Display
				.getDefault().getShells()[0], form, saturnStartNode);
		editDialog.open();
	}

	public void openFormDataDialogFromDoubleClick(SaturnAttribute attribute) {
		SaturnFormDataDialogForDoubleClick dialog = new SaturnFormDataDialogForDoubleClick(Display.getDefault().getShells()[0], attribute);
		dialog.open();
		tableViewer_2.refresh();
	}

	protected void copyLogicKeyList(List<SaturnAttribute> list) {
		List<SaturnAttribute> logicKeyTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			LogicKeyAttribute logic = new LogicKeyAttribute(
					(LogicKeyAttribute) saturn);
			logicKeyTemps.add(logic);
		}
		this.logicKeyTemp = logicKeyTemps;
	}

	protected void copyFormDataList(List<SaturnAttribute> list) {
		List<SaturnAttribute> formDataTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			FormDataAttribute formData = new FormDataAttribute(
					(FormDataAttribute) saturn);
			formDataTemps.add(formData);
		}
		this.formDataTemp = formDataTemps;
	}

	protected void copyStartLimitList(List<SaturnAttribute> list){
		List<SaturnAttribute> listTemp = new ArrayList<SaturnAttribute>();
		for(SaturnAttribute saturn: list){
			ExtendAttributeForLogicKey e = new ExtendAttributeForLogicKey((ExtendAttributeForLogicKey)saturn);
			listTemp.add(e);
		}
		this.extendAttributeForLogicKeyListTemp = listTemp;
	}

	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(SelectionCandidate.ATTRIBUTE_SETTING); 
		newShell.setImage(Activator.getImage(Images.SATURN_ICONS_SMALLNAME)); 
	}

	protected int getShellStyle() {
		return SWT.CLOSE | SWT.RESIZE;
	}

	private void orderFormData(List<SaturnAttribute> list) {
		for (int i = 0; i < list.size(); i++) {
			FormDataAttribute form = (FormDataAttribute) list.get(i);
			form.setId("" + (i + 1));
		}
	}
	
	private void orderExtendAttributeForLogic(List<SaturnAttribute> list){
		for(int i = 0; i < list.size(); i++){
			ExtendAttributeForLogicKey key = (ExtendAttributeForLogicKey)list.get(i);
			key.setId(""+(i+1));
		}
	}
	
	private void errorInformationHint() {
		if ("".equals(activityNameText.getText().trim())) {
			setErrorMessage(Messages.getString("SaturnStartActivityDialog.NameLimit"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else {
			recoverySurface();
		}
	}

	private void recoverySurface() {
		setErrorMessage(null);
		getButton(IDialogConstants.OK_ID).setEnabled(true);
	}

	private void initial() {
		// 基本信息选项卡
		activityIdText.setText(saturnStartNode.getId().trim());
		activityNameText.setText(saturnStartNode.getName().trim());
		startPolicyCombo.setText(RevertCandidate.revertStartPolicy(saturnStartNode.getStartPolicy().trim()));
		timeLimitText.setText(saturnStartNode.getTimeLimit().trim());
		offsetModelCombo.setText(RevertCandidate.revertOffsetModel(saturnStartNode.getOffsetMode().trim()));
		descriptionText.setText(saturnStartNode.getDescription().trim());
//		polymeModeCombo.setText(RevertCandidate.revertPolymeMode(saturnStartNode.getPolymeMode().trim()));
		
		// LogicKey选项卡
		tableViewer.setInput(logicKeyTemp);
		
		// FormData选项卡
		tableViewer_2.setInput(formDataTemp);
		
		// 启动限制
		if("0".equals(this.startLimit.getStartLimitID())){
			directStartButton.setSelection(true);
			regulationStartButton.setSelection(false);
			logicLabel.setEnabled(false);
			logicText.setEnabled(false);
			emplifyLabel.setEnabled(false);
			
			table_5.setEnabled(false);
			insertButton_5.setEnabled(false);
			editButton_5.setEnabled(false);
			deleteButton_5.setEnabled(false);
		}else if("1".equals(this.startLimit.getStartLimitID())){
			directStartButton.setSelection(false);
			regulationStartButton.setSelection(true);
			logicLabel.setEnabled(true);
			logicText.setEnabled(true);
			emplifyLabel.setEnabled(true);
			
			table_5.setEnabled(true);
			insertButton_5.setEnabled(true);
			editButton_5.setEnabled(true);
			deleteButton_5.setEnabled(true);
		}
		logicText.setText(this.startLimit.getLogicKey().trim());
		tableViewer_5.setInput(extendAttributeForLogicKeyListTemp);
	}

	@Override
	protected void buttonPressed(int buttonId) {
		if (saturnStartNode == null) {
			return;
		}
		if (buttonId == IDialogConstants.OK_ID) {
			// 基本信息
			saturnStartNode.setName(activityNameText.getText().trim());
			saturnStartNode.setStartPolicy(RevertCandidate.revertFromFaceToVO(startPolicyCombo.getText().trim()));
			saturnStartNode.setTimeLimit(timeLimitText.getText().trim());
			saturnStartNode.setOffsetMode(RevertCandidate.revertFromFaceToVO(offsetModelCombo.getText().trim()));
			saturnStartNode.setDescription(descriptionText.getText().trim());
			
			// logicKey
			saturnStartNode.setLogicKeyList(logicKeyTemp);
			
			// formData
			saturnStartNode.setFormDataAttributeList(formDataTemp);
			
			// 启动限制
			if(directStartButton.getSelection()==true){
				this.startLimit.setStartLimitID("0");
			}else if(regulationStartButton.getSelection()==true){
				this.startLimit.setStartLimitID("1");
			}
			this.startLimit.setLogicKey(logicText.getText().trim());
			this.startLimit.setExtendAttributeForLogicKey(extendAttributeForLogicKeyListTemp);
			
		}
		super.buttonPressed(buttonId);
	}
}